package com.example.mybaties.testone.service;

import com.example.mybaties.testone.domain.Country;
import com.example.mybaties.testone.mapper.CountryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(value = "countryServiceTarget")
public class CountryServiceImpl implements CountryService {

    @Autowired
    private CountryMapper countryMapper;

    /**
     * 在找到的国家名字后面加上999
     * 其实一条sql就能搞定，这里是故意用2个sql的
     */
    @Override
    public void add999ToCountryName(Long id) {
        Country country = countryMapper.findCountryById(id);
        if (country == null) {
            return;
        }
        country.setName(country.getName() + "999");
        countryMapper.updateCountry(country);
    }

    public void setCountryMapper(CountryMapper countryMapper) {
        this.countryMapper = countryMapper;
    }
}
